{include file="application/admin/view/public/header.html" /}
    <body>
        <div class="x-nav">
          	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" action="{:url('admin/user/sreach')}">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username"  placeholder="请输入分类名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加用户','{:url(\'admin/user/addUser\')}',600,400)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="table table-bordered">
                            <thead>
                              <tr>
                                <th>分类名称</th>
                                <th>封面图</th>
                                <th>描述</th>
                                <th>创建时间</th>
                                <th>状态</th>
                                <th>操作</th>
                              </tr>
                            </thead>
                            <tbody>
                              {volist name="list" id="vo"}
                              <tr>
                                <td>{$vo.name}</td>
                                <td>
                                  <img src="{$vo.cover_img}" alt="" style="width: 20px;">
                                </td>
                                 <td>{$vo.description}</td>
                                <td>{$vo.create_time|date='Y-m-d H:i:s'}</td>
                                <td class="td-status">
                                    {if $vo.status eq 1}
                                    <span style="color: green;">已启用</span>
                                    {else/}
                                    <span style="color: red;">已禁用</span>
                                    {/if}
                                </td>
                                <td>
                                  {if $vo.status eq 1}
                                  <a href="javascript:;" onclick="member_stop(this,{$vo.id})" title="禁用">禁用</a> |
                                  {else /}
                                  <a href="javascript:;" onclick="member_stop(this,{$vo.id})" title="启用">启用</a> |
                                  {/if}
                                  <a href="javascript:;" onclick="xadmin.open('编辑','{:url(\'admin/user/editUser\')}?uid={$vo.id}')">修改</a> |
                                  <a href="javascript:;" onclick="member_del(this,{$vo.id})">删除</a>
                                </td>
                              </tr>
                              {/volist}
                            </tbody>
                          </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
								{$list|raw}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        
        // 监听全选
        form.on('checkbox(checkall)', function(data){
          console.log(data);
          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 

      });

       /*用户-禁用-启用*/
      function member_stop(obj,id){
        var msg = $(obj).attr('title');
          layer.confirm('确认要' + msg + '吗？',function(index){
            $.ajax({
              url:'{:url("admin/user/ProhibitOrEnable")}',
              type:'get',
              dataType:'json',
              data:'uid=' + id + '&msg=' + msg,
              success: res => {
                if (res.code == 1) {
                  if (msg == '禁用') {
                    console.log(obj);
                    $(obj).attr('title', '启用')
                    $(obj).html('启用');
                    $(obj).parents("tr").find(".td-status").html('<span style="color: red;">已禁用</span>');
                  } else {
                    $(obj).attr('title', '禁用')
                    $(obj).html('禁用');
                    $(obj).parents("tr").find(".td-status").html('<span style="color: green;">已启用</span>');
                  }
                  layer.msg(res.msg,{icon: 6,time:1000});
                } else {
                  layer.msg('失败!',{icon: 5,time:1000});
                }
              }
            });
          });
          return false;
      }

      /*用户-删除*/
      function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
              url:'{:url("admin/user/delUser")}',
              type:'get',
              dataType:'json',
              data:'uid=' + id,
              success: res => {
                if (res.code == 1) {
                  $(obj).parents("tr").remove();
                  layer.msg(res.msg, {icon:1, time:1000});
                } else {
                  layer.msg(res.msg, {icon:2, time:1000});
                }
              }
            });
            
        });
        return false;
      }

      //批量删除
      function delAll (argument) {
        var ids = [];
        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
        if (ids.length == 0) {
          layer.msg('没有选择需要删除的', {icon: 0});
          return;
        }
        layer.confirm('确认要删除吗？' + ids.toString(),function(index){
            $.ajax({
              url:'{:url("admin/user/delAllUser")}',
              type:'post',
              dataType:'json',
              data:{
                ids:ids.toString()
              },
              success: res => {
                if (res.code == 1) {
                  layer.msg(res.msg, {icon: 1});
                  $(".layui-form-checked").not('.header').parents('tr').remove();
                } else {
                  layer.msg(res.msg, {icon: 2});
                }
              }
            });
        });
      }

    </script>
</html>